import {captchaStore} from 'WE/Stores';

class CaptchaService {
  listeners = [];

  constructor() {}

  async getList() {
    return await captchaStore.getValues();
  }

  async removeElement({value}) {
    let newVar = await captchaStore.delValue(value);
    this.listeners.forEach(fun => fun('removeElement', newVar));
    return newVar;
  }

  async addCaptchaData(data) {
    await captchaStore.addValue(data);
    this.listeners.forEach(fun => fun('addCaptchaData', data));
  }

  addListener(list) {
    if (!this.listeners.includes(list)) {
      this.listeners.push(list);
    }
  }
}

export default new CaptchaService();
